import Api from '../../../../utils/httpImpl';
const api = new Api();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    chapterList: [],
    subjectId: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if(options.id) {
      this.setData({
        subjectId: options.id,
      });
    }
    this.getData();
  },
  // 获取数据
  async getData() {
    let _json = {
      subject_id: this.data.subjectId
    };
    const result = await api.getChapter(_json);
    this.setData({
      chapterList: result.chapters
    });
  },
  //去答题
  toAnswer(e) {
    let _id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/doExercise/doExercise?id=${_id}`,
    });
  }
})